package com.yunxin.core.infra.persistence.repository.order;


import com.yunxin.core.application.dto.order.ChannelPromotionTwoUvStatisticsVo;
import com.yunxin.core.domain.model.order.OrderUserUv;
import com.yunxin.core.domain.model.order.OrderUserUvRepository;
import com.yunxin.core.infra.persistence.converter.OrderConverter;
import com.yunxin.core.infra.persistence.entity.order.OrderUserUvDO;
import com.yunxin.core.infra.persistence.mapper.order.OrderUserUvExtendMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.Date;

/**
 * @author zero°
 * @since 2023-07-17
 */
@Repository
@RequiredArgsConstructor
public class OrderUserUvRepositoryImpl implements OrderUserUvRepository {

    private final OrderUserUvExtendMapper orderUserUvExtendMapper;

    private  final OrderConverter orderConverter;

    @Override
    public boolean saveOrderUserUv(OrderUserUv orderUserUv) {
        OrderUserUvDO orderUserUvDO = orderConverter.formOrderUserUv(orderUserUv);
        int count = orderUserUvExtendMapper.insertSelective(orderUserUvDO);
        return count > 0;
    }

    @Override
    public boolean updateSubmitTime(Long id) {
        int count = orderUserUvExtendMapper.updateOrderUserUvSubmitTimeById(id, new Date());
        return count > 0;
    }

    @Override
    public Long getOrderUserUvIdByUserAndProduct(String userCode, Long productId) {
        return orderUserUvExtendMapper.getOrderUserUvIdByUserAndProduct(userCode, productId);
    }

    /**
     * 查询二次uv需要保存的新秀
     * @param userCode
     * @param productId
     * @param channelId
     * @return
     */
    @Override
    public ChannelPromotionTwoUvStatisticsVo selectOrderUserDetail(String userCode,Long productId,Long channelId) {
        return orderUserUvExtendMapper.selectOrderUserDetail(userCode,productId,channelId);
    }

    /**
     * 保存二次uv统计数据
     *
     * @param dto
     */
    @Override
    public void saveOrderUserTwoUv(ChannelPromotionTwoUvStatisticsVo dto) {
        orderUserUvExtendMapper.saveOrderUserTwoUv(dto);
    }


}
